package com.music.server.controller;


import com.music.server.pojo.ListSong;
import com.music.server.service.ListSongService;
import com.music.server.utils.ResultVo;
import com.music.server.vo.ListSongVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 歌单与歌曲对应包含歌曲列表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-03-09
 */
@RestController
@RequestMapping("listSong")
public class ListSongController {

    @Autowired
    private ListSongService listSongService;

    /**
     * 添加歌单与歌曲对应信息
     * @return
     */
    @PostMapping("save")
    public ResultVo save(@RequestBody ListSong listSong){
        boolean save = listSongService.save(listSong);
        if (save) return ResultVo.ok();
        return ResultVo.error();
    }

    /**
     * 查询所有的歌单与歌曲对应信息
     * @return
     */
    @GetMapping("list")
    public ResultVo list(){
        List<ListSong> list = listSongService.list();
        return ResultVo.ok().data("list",list);
    }

    /**
     * 分页条件查询所有的歌单与歌曲对应信息
     * @return
     */
    @PostMapping("page/{pageNum}/{size}")
    public ResultVo page(@PathVariable Integer pageNum,@PathVariable Integer size,@RequestBody ListSongVo listSongVo){

        return ResultVo.ok().data("page",listSongService.page(pageNum,size,listSongVo));
    }


    /**
     * 删除歌单与歌曲对应信息及对应的所有信息
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public ResultVo delete(@PathVariable Integer id){
        boolean delete = listSongService.removeById(id);
        if (delete) return ResultVo.ok();
        return ResultVo.error();
    }

}

